package com.wuyangnju.lj.simulation.master.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wuyangnju.lj.simulation.common.CommonStrings;
import com.wuyangnju.lj.simulation.master.service.ComputionException;
import com.wuyangnju.lj.simulation.master.service.ComputionService;

@SuppressWarnings("serial")
public class ComputionStatusServlet extends HttpServlet {
	private static final Log log = LogFactory
			.getLog(ComputionStatusServlet.class);

	private ComputionService computionService;
	{
		computionService = ComputionService.get();
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/plain");

		String computionStatus = null;
		try {
			computionStatus = computionService.getComputionStatus();
			resp.getWriter().println(computionStatus);
			log.info("compution status retrive: " + computionStatus);
		} catch (ComputionException e) {
			resp.getWriter().println(
					CommonStrings.COMPUTION_EXCEPTION + ": " + e.getMessage());
			log.warn(CommonStrings.COMPUTION_EXCEPTION, e);
		}
	}
}
